.TH std::end(std::valarray) 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::end(std::valarray) \- std::end(std::valarray)

.SH Synopsis
   template< class T >                          \fB(1)\fP \fI(since C++11)\fP
   /* see below */ end( valarray<T>& v );
   template< class T >                          \fB(2)\fP \fI(since C++11)\fP
   /* see below */ end( const valarray<T>& v );

   The overload of std::end for valarray returns an iterator of unspecified type
   referring to the one past the last element in the numeric array.

   1) The return type must
     * meet the requirements of mutable LegacyRandomAccessIterator,

     * model contiguous_iterator,   \fI(since C++20)\fP

     * have a member type value_type, which is T, and
     * have a member type reference, which is T&.
   2) The return type must
     * meet the requirements of constant LegacyRandomAccessIterator,

     * model contiguous_iterator,   \fI(since C++20)\fP

     * have a member type value_type, which is T, and
     * have a member type reference, which is const T&.

   The iterator returned from this function is invalidated when the member function
   resize() is called on v or when the lifetime of v ends, whichever comes first.

.SH Parameters

   v - a numeric array

.SH Return value

   Iterator to one past the last value in the numeric array.

.SH Exceptions

   May throw implementation-defined exceptions.

.SH Notes

   Unlike other functions that take std::valarray arguments, end() cannot accept the
   replacement types (such as the types produced by expression templates) that may be
   returned from expressions involving valarrays: std::end(v1 + v2) is not portable,
   std::end(std::valarray<T>(v1 + v2)) has to be used instead.

   The intent of this function is to allow range for loops to work with valarrays, not
   to provide container semantics.

.SH Example


// Run this code

 #include <algorithm>
 #include <iostream>
 #include <valarray>

 int main()
 {
     const std::valarray<char> va
     {
         'H', 'e', 'l', 'l', 'o',
         ',', ' ',
         'C', '+', '+', '!', '\\n'
     };

     std::for_each(std::begin(va), std::end(va),
                   [](char c){ std::cout << c; });
 }

.SH Output:

 Hello, C++!

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to              Behavior as published              Correct behavior
                       1. end() was required to support replacement
   LWG 2058 C++11      types                                           1. not required
                       2. it was unspecified when the returned         2. specified
                       iterators will be invalidated

.SH See also

   std::begin(std::valarray) overloads std::begin
   \fI(C++11)\fP                   \fI(function template)\fP
